<!doctype html>
<html>
<head>
	<meta charset="utf-8" />
	<link rel="stylesheet" type="text/css" href="/css/bind.css" />
	<title>绑定设备</title>
	<style type="text/css">
	</style>
</head>
<body>
	<!-- 微信接口数据值调用 -->
	<input type="hidden" value="{{ $jssdkSignPackage['appId'] or 'default' }}" class="appId_val" />
	<input type="hidden" value="{{ $jssdkSignPackage['nonceStr'] or 'default' }}" class="nonceStr_val" />
	<input type="hidden" value="{{ $jssdkSignPackage['timestamp'] or 'default' }}" class="timestamp_val" />
	<input type="hidden" value="{{ $jssdkSignPackage['signature'] or 'default' }}" class="signature_val" />
	<section class="bind pages">
		<img src="/img/okLogo.png" />
		<p>个人信息填写成功，点击“绑定水机”按钮，扫描水机上二维码绑定设备</p>
		<a class="okBtn">绑定水机</a>
	</section>
	<!-- 提交信息服务器反馈信息-->
	<section class="hint_bg">
		<section class="hint_box">
			<p class="hint_text"></p>
			<section class="hint_btn">确定</section>
		</section>
	</section>
	<section class="hint_bg2">
		<section class="hint_box2">
			<p class="hint_text2">选择的设备类型与当前扫码的设备类型不一致</p>
			<section class="hint_btn2">确定</section>
		</section>
	</section>
	<script src="/js/jquery.min.js"></script>
	<script src="/js/public.js"></script>
	<script src="/js/jweixin-1.0.0.js"></script>
	<script type="text/javascript">
		wx.config({
		    debug:false,
		    appId:$('.appId_val').val(),
		    timestamp:$('.timestamp_val').val(),
		    nonceStr:$('.nonceStr_val').val(),
		    signature:$('.signature_val').val(),
		    jsApiList:['scanQRCode']
		});
		$(".okBtn").click(function(){
			wx.scanQRCode({
			    needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
			    scanType: ["qrCode"], // 可以指定扫二维码还是一维码，默认二者都有
			    success: function (res) {
				    if (res.errMsg === "scanQRCode:ok"){
					    $.ajax({
					    	url:"/api/device/{{ $type }}/bind",
					    	type:"post",
					    	data:{device_code:res.resultStr},
					    	dataType:'json',
					    	success:function(data){
					    		if(data.status.errCode == 0||data.status.errCode == 20002){
					    			hint("绑定成功!");
			    					setTimeout(function(){
			    						window.location.href = "/device/{{ $type }}/state?"+new Date().getTime();
			    					},300);
					    		}else if(data.status.errCode == 21002){
					    			$(".hint_bg2").show();
					    			$(".hint_bg2").height($(window).height());
					    			$(".hint_btn2").unbind('click').click(function(){
					    				$(".hint_bg2").hide();
					    				window.location.href = "/index";
					    			});
					    		}else{					    			
					    			hint(data.status.message);
					    		}
					    	}
					    });
				    }
				}
			});
		});
	</script>
</body>
</html>